package com.zw.pdm.module.est.controller;

import com.zw.pdm.base.BaseController;
import com.zw.pdm.common.JsonResult;
import com.zw.pdm.entity.est.Card;
import com.zw.pdm.module.basic.service.DictCommonService;
import com.zw.pdm.module.est.service.CardQueryService;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

import static com.zw.pdm.constant.Constant.GROUP_SPECTYPE;

/**
 * @Description: 工艺卡查询
 *
 * @Author: China.sgl
 * @Date: 2020/8/3 16:11
 */
@Controller
@RequestMapping("/est/query")
@SuppressWarnings("all")
public class CardQueryController extends BaseController {

    @Autowired
    private CardQueryService cardQueryService;
    @Autowired
    private DictCommonService dictCommonService;

    @GetMapping
    @RequiresPermissions(value = {"est:query:view"}, logical = Logical.OR)
    public String page(Model model) {
        model.addAttribute("specials", dictCommonService.findDictByGroupName(GROUP_SPECTYPE));
        return "est/query/page";
    }

    /** 列表 */
    @ResponseBody
    @PostMapping("/list")
    public JsonResult cardList(Card card) {
        startPage();
        List<Card> list = cardQueryService.findWithCardQuery(card);
        return jsonResult(list);
    }

}
